VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "IScreen_Level"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

'This is a snap-in class for `Project.GameScreen`, shown on screen
Implements IScreen

'--- Graphics -----------------------------------------------------------------------
Private StatusLife As New ImageTGA        'The symbol for a life
Private StatusHighScore As New ImageTGA   'The "Hi" light
Private StatusMultiplier As New ImageTGA  'The 'x2' light
Private StatusCookies As New ImageTGA     'The cookie symbol in the bar
Private StatusTime As New ImageTGA        'The "time:" text
Private StatusTimeColon As New ImageTGA   'The blinking colon in the time

'====================================================================================
'CLASS Initialize
'====================================================================================
Private Sub Class_Initialize()
    StatusLife.LoadTGA32 AppPath & "\gfx\HUD\StatusLife.tga"
    StatusHighScore.LoadTGA32 AppPath & "\gfx\HUD\StatusHighScore.tga"
    StatusMultiplier.LoadTGA32 AppPath & "\gfx\HUD\StatusMultiplier.tga"
    StatusCookies.LoadTGA32 AppPath & "\gfx\HUD\StatusCookies.tga"
    StatusTimeColon.LoadTGA32 AppPath & "\gfx\HUD\StatusTimeColon.tga"
    StatusTime.LoadTGA32 AppPath & "\gfx\HUD\StatusTime.tga"
End Sub

'====================================================================================
'ISCREEN Animate: Animate and move the sprites in the level
'====================================================================================
Private Sub IScreen_Animate()
    'Some animation tasks refer to the level structure, &c. Defer to the level _
     class that manages the real tasks. (This class is simply the snap-in needed _
     to define a visible game screen, it cannot have all the extra public _
     properties & functions needed)
    Level.Animate
    
    '--- Start ----------------------------------------------------------------------
    If ScreenMode = SM_Start Then
        'If the level has loaded and gameplay is about to start, show the _
         "Ready", "Set", "Go" Messages...
        If Status.IsBottomAnimationFinished = True Then
            Select Case ModeStep
                Case 0 '.............................................................
                    'Show the starting message
                    Status.SetMessageBottom "Ready?", SLIDECENTER, 32, True
                    ModeStep = 1

                Case 1 '.............................................................
                    'If the message was "Ready?", then show the next message
                    Status.SetMessageBottom "Set...", SLIDEDOWN, 32, True
                    ModeStep = 2

                Case 2 '.............................................................
                    'Start the gameplay!
                    Status.SetMessageBottom "GO!!!", SLIDEUP, 32, True
                    ScreenMode = SM_Play

            End Select
        End If
    
    '--- Pause ----------------------------------------------------------------------
    ElseIf ScreenMode = SM_Pause Then
        Select Case ModeStep
            Case 0 '.................................................................
                'Close the doors partially
                Status.CloseDoors (STATUS_SPEED_NUDGE)
                If Status.ScreenSplit <= 176 Then Status.ScreenSplit = 176: ModeStep = 1

            Case 1 '.................................................................
                'Do squit. Whilst paused nothing happens

            Case 2 '.................................................................
                'When the user un-pauses, modestep is set to 2 to jump here:
                'Slide opent the doors, and go back to play mode
                If Status.OpenDoors(STATUS_SPEED_QUICK) Then ScreenMode = SM_Play

        End Select

    '--- Level Complete -------------------------------------------------------------
    ElseIf ScreenMode = SM_Complete Then
        Select Case ModeStep
            Case 0 '.................................................................
                'Close the doors on the level
                If Status.CloseDoors(STATUS_SPEED_STANDARD) Then ModeStep = 1

            Case 1 '.................................................................
                'Show the Level Complete screen
                If Status.IsBottomAnimationFinished Then
                    Game.StartLevelCompleteScreen
                End If

        End Select

    '--- Game Over ------------------------------------------------------------------
    ElseIf ScreenMode = SM_GameOver Then
        Select Case ModeStep
            Case 0 '.................................................................
                'Close the doors on the level slowly
                If Status.CloseDoors(STATUS_SPEED_NUDGE) Then ModeStep = 1

            Case 1 '.................................................................
                'Display the GameOver message...
                Status.SetMessageBottom "=== GAME OVER ===", SLIDEDOWN, 64, True
                ModeStep = 2

            Case 2 '.................................................................
                'Once the game over message has cleared...
                If Status.IsBottomAnimationFinished Then
                    '!//If the player scored a new highscore...
                    '//If (Game.Score > Game.HiScore) Then
                    '//    Status.SetMessageBottom "*** NEW HIGH SCORE ***", SA_SLIDECENTER, 50, True
                    '//    ModeStep = 3
                    '//Else
                        '!//Return to the title screen
                        'If the game was played from a level file on disk, close the
                        'program after play.
                        If Game.IsSingleLevel Then
                            Startup.ExitGame
                        Else
                            '!//Game.StartTitleScreen
                            Project.StartHighScoreScreen False
                        End If
                    '//End If
                End If

            Case 3 '.................................................................
                '!//Once the New High Score message has finished, change to the high
                'scores game screen
                If Status.IsBottomAnimationFinished Then Project.StartTitleScreen

        End Select

    '--- Quit -----------------------------------------------------------------------
    ElseIf ScreenMode = SM_Quit Then
        Select Case ModeStep
            Case 0 '.................................................................
                'Close the doors on the level
                If Status.CloseDoors(STATUS_SPEED_NUDGE) Then ModeStep = 1

            Case 1 '.................................................................
                'Return to the title screen
                Status.ClearMessageBottom: Status.ClearMessageTop
                Level.Paused = False
                If Game.IsSingleLevel Then
                    Startup.ExitGame
                Else
                    Project.StartTitleScreen
                End If

        End Select
    End If '-------------------------------------------------------------------------
End Sub

'====================================================================================
'ISCREEN Render: Draw the level
'====================================================================================
Private Sub IScreen_Render(ByVal hDC As Long)
    Level.Render hDC
End Sub

'====================================================================================
'ISCREEN RenderTopBar: Render the top status bar display
'====================================================================================
Private Sub IScreen_RenderTopBar(ByVal hDC As Long)
    '--- Game Over ------------------------------------------------------------------
    If ScreenMode >= SM_GameOver Then
        'On Game Over, only show the score on the top
        Status.DrawDigits hDC, 2, Game.Score, 6
        'Hi-Score?
        If (Game.Score > Level.Data.HighScores.BestScores.Score(0)) Then StatusHighScore.Draw hDC, 138, 3
    
    
    '--- Intro ----------------------------------------------------------------------
    ElseIf ScreenMode > SM_Intro Then
        'Score ......................................................................
        Status.DrawDigits hDC, 2, Game.Score, 6
        'Hi-Score?
        If (Game.Score > Level.Data.HighScores.BestScores.Score(0)) Then
            StatusHighScore.Draw hDC, 138, 3
        End If
        'Is the 2x Multiplier power up in effect?
        If Level.PickupCountdown > 0 And Level.PickupType = PT_GOOD_MULTIPLIER Then
            StatusMultiplier.Draw hDC, 138, 13
        End If
        
        'Cookies ....................................................................
        StatusCookies.Draw hDC, 390, 4
        Status.DrawDigits hDC, 428, Level.Data.CookieCount, 3
        
        'Elapsed time ...............................................................
        Dim tSeconds As String, tMinutes As String
        tSeconds = Trim(Str(Level.RemainingTime Mod 60))
        tMinutes = Trim(Str(Level.RemainingTime \ 60))
        'Draw on the "time:" text
        StatusTime.Draw hDC, 502, 6
    
        'Seconds ....................................................................
        If Len(tSeconds) = 1 And tMinutes = "0" Then
            'If one digit and minutes = 0, use unlit 0
            Status.DrawDigits hDC, 593, tSeconds, 2
            
        ElseIf Val(tSeconds) < 10 Then
            'If one digit and minutes > 0, use lit 0
            Status.DrawDigits hDC, 593, "0" & tSeconds, 2
            
        Else
            'Else, just draw on both digits
            Status.DrawDigits hDC, 593, tSeconds, 2
            
        End If
        
        'Time Colon .................................................................
        If ScreenMode = SM_Play Then
            Static Blinken As Long
            Blinken = (Blinken + 1) Mod 32
            If Blinken < 12 Then
                'Draw a solid colon
                StatusTimeColon.DrawEx hDC, 586, 9, 3, 14, 0, 14
            Else
                'Draw an unlit colon
                StatusTimeColon.DrawEx hDC, 586, 9, 3, 14, 0, 0
            End If
        Else
            'If the timer has frozen (died, level complete...) then draw unlit colon
            StatusTimeColon.DrawEx hDC, 586, 9, 3, 14, 0, 14
        End If
    
        'Minutes ....................................................................
        If tMinutes = "0" Then
            'If 0, use unlit digits
            Status.DrawDigits hDC, 561, "", 1
            
        Else
            'Otherwise display the number
            Status.DrawDigits hDC, 561, tMinutes, 1
            
        End If
    End If '-------------------------------------------------------------------------
End Sub

'====================================================================================
'ISCREEN RenderBottomBar: Render the bottom status bar display
'====================================================================================
Private Sub IScreen_RenderBottomBar(ByVal hDC As Long)
    Dim K As Long
    
    'Don't display the lives at the bottom until gameplay has started
    If ScreenMode > SM_Start Then
        'Draw the Life icons on the bottom
        For K = 1 To Game.Lives: StatusLife.Draw hDC, 3 + ((K - 1) * 34), 1: Next K
        'If a power up/down is in effect, show the countdown
        If Level.PickupCountdown > 0 Then Status.DrawDigits hDC, 596, Level.PickupCountdown, 2
    End If
End Sub

'====================================================================================
'ISCREEN HandleKey: When the player presses keys, do things
'====================================================================================
Private Sub IScreen_HandleKey(ByVal KeyCode As Integer, ByVal Shift As Integer)
    If (KeyCode = vbKeyEscape Or KeyCode = vbKeyP) Or _
       (Level.Paused = True And (KeyCode = vbKeySpace Or KeyCode = vbKeyReturn)) Then
        'If in level, press ESC to pause/unpause
        If ScreenMode = SM_Play Then
            'Pause...
            Level.Paused = True
            ScreenMode = SM_Pause

        ElseIf ScreenMode = SM_Pause Then
            'Unpause... (see Animate function)
            Level.Paused = False
            ScreenMode = SM_Pause: ModeStep = 2

        End If

    ElseIf KeyCode = vbKeyQ Then
        'If the player presses Q (if paused) Quit the game
        If ScreenMode = SM_Pause And KeyCode = vbKeyQ Then
            ScreenMode = SM_Quit
        End If

    End If
End Sub

'====================================================================================
'ISCREEN HandleMouseMove
'====================================================================================
Private Sub IScreen_HandleMouseMove(ByVal MouseX As Single, ByVal MouseY As Single)
    'This screen ignores mouse movements. This function has to be here in order to
    'comply with the IScreen Interface 'IScreen.cls'
End Sub

'====================================================================================
'ISCREEN HandleMouseClick
'====================================================================================
Private Sub IScreen_HandleMouseClick(ByVal Button As Integer, ByVal Shift As Integer, ByVal MouseX As Integer, ByVal MouseY As Integer)
    'This screen ignores mouse clicks. This function has to be here in order to
    'comply with the IScreen Interface 'IScreen.cls'
End Sub

'====================================================================================
'Class Terminate
'====================================================================================
Private Sub Class_Terminate()
    Set StatusLife = Nothing
    Set StatusHighScore = Nothing
    Set StatusMultiplier = Nothing
    Set StatusCookies = Nothing
    Set StatusTime = Nothing
    Set StatusTimeColon = Nothing
End Sub

'=== END ============================================================================
'This work is licenced under the Creative Commons Attribution 2.5 License
